home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 February / PCWorld_2004-02_cd.bin / software / vyzkuste / inno / isetup-4.0.10.exe / {app} / Examples / CodeExample1.iss < prev    next >
Text File  |  2003-09-21  |  4KB  |  113 lines

  1. ; -- CodeExample1.iss --
  2. ;
  3. ; This script shows various things you can achieve using a [Code] section
  4.  
  5. [Setup]
  6. AppName=My Program
  7. AppVerName=My Program version 1.5
  8. DefaultDirName={code:MyConst}\My Program
  9. DefaultGroupName=My Program
  10. UninstallDisplayIcon={app}\MyProg.exe
  11.  
  12. [Files]
  13. Source: "MyProg.exe"; DestDir: "{app}"; Check: MyProgCheck
  14. Source: "MyProg.hlp"; DestDir: "{app}"; Check: MyProgCheck
  15. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
  16.  
  17. [Icons]
  18. Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
  19.  
  20. [Code]
  21. var
  22.   MyProgChecked: Boolean;
  23.   MyProgCheckResult: Boolean;
  24.   FinishedInstall: Boolean;
  25.  
  26. function InitializeSetup(): Boolean;
  27. begin
  28.   Result := MsgBox('Script.InitializeSetup:' #13#13 'Setup is initializing. Do you really want to start setup?', mbConfirmation, MB_YESNO) = idYes;
  29.   if Result = False then
  30.     MsgBox('Script.InitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
  31. end;
  32.  
  33. procedure DeInitializeSetup();
  34. var
  35.   FileName: String;
  36.   ErrorCode: Integer;
  37. begin
  38.   if FinishedInstall then begin
  39.     if MsgBox('Script.DeInitializeSetup:' #13#13 'The [Code] scripting demo has finished. Do you want to uninstall My Program now?', mbConfirmation, MB_YESNO) = idYes then begin
  40.       FileName := ExpandConstant('{uninstallexe}');
  41.       if not InstShellExec(FileName, '', '', SW_SHOWNORMAL, ErrorCode) then
  42.         MsgBox('Script.DeInitializeSetup:' #13#13 'Execution of ''' + FileName + ''' failed. ' + SysErrorMessage(ErrorCode) + '.', mbError, MB_OK);
  43.     end else
  44.       MsgBox('Script.DeInitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
  45.   end;
  46. end;
  47.  
  48. procedure CurStepChanged(CurStep: Integer);
  49. begin
  50.   if CurStep = csFinished then
  51.     FinishedInstall := True;
  52. end;
  53.  
  54. function NextButtonClick(CurPage: Integer): Boolean;
  55. var
  56.   ErrorCode: Integer;
  57. begin
  58.   case CurPage of
  59.     wpSelectDir:
  60.       MsgBox('Script.NextButtonClick:' #13#13 'You selected: ''' + WizardDirValue + '''.', mbInformation, MB_OK);
  61.     wpSelectProgramGroup:
  62.       MsgBox('Script.NextButtonClick:' #13#13 'You selected: ''' + WizardGroupValue + '''.', mbInformation, MB_OK);
  63.     wpReady:
  64.       begin
  65.         if MsgBox('Script.NextButtonClick:' #13#13 'Using the script, files can now be extracted before the installation starts. For example we could extract ''MyProg.exe'' now and run it.' #13#13 'Do you want to do this?', mbConfirmation, MB_YESNO) = idYes then begin
  66.           if ExtractTemporaryFile('myprog.exe') then begin
  67.             if not InstExec(ExpandConstant('{tmp}\myprog.exe'), '', '', True, False, SW_SHOWNORMAL, ErrorCode) then
  68.               MsgBox('Script.NextButtonClick:' #13#13 'The file could not be executed. ' + SysErrorMessage(ErrorCode) + '.', mbError, MB_OK);
  69.           end else
  70.             MsgBox('Script.NextButtonClick:' #13#13 'The file could not be extracted.', mbError, MB_OK);
  71.         end;
  72.         BringToFrontAndRestore();
  73.         MsgBox('Script.NextButtonClick:' #13#13 'The normal installation will now start.', mbInformation, MB_OK);
  74.       end;
  75.   end;
  76.  
  77.   Result := True;
  78. end;
  79.  
  80. function SkipCurPage(CurPage: Integer): Boolean;
  81. begin
  82.   case CurPage of
  83.     wpInfoBefore:
  84.       Result := MsgBox('Script.SkipCurPage:' #13#13 'Do you want to skip the ''InfoBefore'' page?', mbConfirmation, MB_YESNO or MB_DEFBUTTON2) = idYes;
  85.     else
  86.       Result := False;
  87.   end;
  88. end;
  89.  
  90. procedure CurPageChanged(CurPage: Integer);
  91. begin
  92.   case CurPage of
  93.     wpWelcome:
  94.       MsgBox('Script.CurPageChanged:' #13#13 'Welcome to the [Code] scripting demo. This demo will show you some possibilities of the new scripting support.' #13#13 'The scripting engine used is Innerfuse Pascal Script by Carlo Kok from Innerfuse. See http://www.carlo-kok.com/ifps3.php for more information.', mbInformation, MB_OK);
  95.     wpFinished:
  96.       MsgBox('Script.CurPageChanged:' #13#13 'Welcome to final page of this demo. Click Finish to exit.', mbInformation, MB_OK);
  97.   end;
  98. end;
  99.  
  100. function MyProgCheck(): Boolean;
  101. begin
  102.   if not MyProgChecked then begin
  103.     MyProgCheckResult := MsgBox('Script.MyProg:' #13#13 'Do you want to install MyProg.exe and MyProg.hlp?', mbConfirmation, MB_YESNO) = idYes;
  104.     MyProgChecked := True;
  105.   end;
  106.   Result := MyProgCheckResult;
  107. end;
  108.  
  109. function MyConst(Default: String): String;
  110. begin
  111.   Result := ExpandConstant('{pf}');
  112. end;
  113.